<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:import href="../utilities/get-tomorrow.xsl"/>

<xsl:template name="select-print">
	<xsl:param name="tomorrow">
		<xsl:call-template name="next-day">
			<xsl:with-param name="date" select="$today"/>
		</xsl:call-template>
	</xsl:param>
	
	<select id="admin_print">
		<option value="Print Schedule">make a selection</option>
		<option disabled="disabled" value="">------------</option>
		<!--xsl:if test="$current-page = 'admin-print'"-->
		<xsl:choose>
			<xsl:when test="$entry-id = 'today' or $entry-id = $today">
				<option value="today" selected="selected">Today</option>
			</xsl:when>
			<xsl:otherwise>
				<option value="today">Today</option>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:choose>
			<xsl:when test="$entry-id = $tomorrow or $entry-id = 'tomorrow'">
				<option value="tomorrow" selected="selected">Tomorrow</option>
			</xsl:when>
			<xsl:otherwise>
				<option value="tomorrow">Tomorrow</option>
			</xsl:otherwise>
		</xsl:choose>
	</select>
</xsl:template>

<xsl:template match="admin-print-schedule" mode="print-tomorrow">
	<xsl:param name="tomorrow">
		<xsl:call-template name="next-day">
			<xsl:with-param name="date" select="$today"/>
		</xsl:call-template>
	</xsl:param>
	<xsl:param name="week-day">
		<xsl:call-template name="get-day-of-the-week-name">
			<xsl:with-param name="date" select="$tomorrow"/>
		</xsl:call-template>
	</xsl:param>
	
	<div class="calendar-head">
		<h2>Print Tomorrow's Schedule</h2>
	</div>
	
	<xsl:choose>
		<xsl:when test="error = 'No records found.'">
			<h4>There are no appointments for tomorrow.</h4>
		</xsl:when>
		<xsl:otherwise>
			<h4>
				<xsl:value-of select="normalize-space($week-day)"/>
				<xsl:text>, </xsl:text>
				<xsl:call-template name="get-formatted-date">
					<xsl:with-param name="date" select="$tomorrow"/>
				</xsl:call-template>
			</h4>
			<table id="pricingTable" cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<th class="table-th-nosort">Appointment Time</th>
						<th class="table-th-nosort">Name (Last, First)</th>
						<th class="table-th-nosort">Client Username</th>
						<th class="table-th-nosort">Cell Phone</th>
						<th class="table-th-nosort">Home Phone</th>
					</tr>
				</thead>
				<tbody>
					<xsl:apply-templates select="entry[appointment-date = $tomorrow]" mode="tr"/>
				</tbody>
			</table>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template match="admin-print-schedule" mode="print-other">
	<xsl:param name="week-day">
		<xsl:call-template name="get-day-of-the-week-name">
			<xsl:with-param name="date" select="$entry-id"/>
		</xsl:call-template>
	</xsl:param>
	
	<div class="calendar-head">
		<h2>Print Schedule</h2>
	</div>
	
	<xsl:choose>
		<xsl:when test="error = 'No records found.'">
			<h4>There are no appointments on this date.</h4>
		</xsl:when>
		<xsl:otherwise>
			<h4>
				<xsl:value-of select="normalize-space($week-day)"/>
				<xsl:text>, </xsl:text>
				<xsl:call-template name="get-formatted-date">
					<xsl:with-param name="date" select="$entry-id"/>
				</xsl:call-template>
			</h4>
			<table id="pricingTable" cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<th class="table-th-nosort">Appointment Time</th>
						<th class="table-th-nosort">Name (Last, First)</th>
						<th class="table-th-nosort">Client Username</th>
						<th class="table-th-nosort">Cell Phone</th>
						<th class="table-th-nosort">Home Phone</th>
					</tr>
				</thead>
				<tbody>
					<xsl:apply-templates select="entry[appointment-date = $entry-id]" mode="tr"/>
				</tbody>
			</table>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template match="admin-print-schedule" mode="print-today">
	<xsl:param name="week-day">
		<xsl:call-template name="get-day-of-the-week-name">
			<xsl:with-param name="date" select="$today"/>
		</xsl:call-template>
	</xsl:param>
	
	<div class="calendar-head">
		<h2>Print Today's Schedule</h2>
	</div>
	
	<xsl:choose>
		<xsl:when test="error = 'No records found.'">
			<h4>There are no appointments for today.</h4>
		</xsl:when>
		<xsl:otherwise>
			<h4>
				<xsl:value-of select="normalize-space($week-day)"/>
				<xsl:text>, </xsl:text>
				<xsl:call-template name="get-formatted-date">
					<xsl:with-param name="date" select="$today"/>
				</xsl:call-template>
			</h4>
			<table id="pricingTable" cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<th class="table-th-nosort">Appointment Time</th>
						<th class="table-th-nosort">Name (Last, First)</th>
						<th class="table-th-nosort">Client Username</th>
						<th class="table-th-nosort">Cell Phone</th>
						<th class="table-th-nosort">Home Phone</th>
					</tr>
				</thead>
				<tbody>
					<xsl:apply-templates select="entry[appointment-date = $today]" mode="tr"/>
				</tbody>
			</table>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template match="admin-print-schedule/entry" mode="tr">
	<xsl:param name="client" select="email"/>
	
	<tr>
		<td>
			<xsl:call-template name="get-formatted-time">
				<xsl:with-param name="time" select="appointment-date/@time"/>
			</xsl:call-template>
		</td>
		<td>
			<xsl:value-of select="name"/>
		</td>
		<td>
			<xsl:value-of select="email"/>
		</td>
		<xsl:apply-templates select="/data/admin-clients/entry[email-address = $client]" mode="cell"/>
	</tr>
</xsl:template>

<xsl:template match="/data/admin-clients/entry" mode="cell">
	<td>
		<xsl:value-of select="client-mobile-phone"/>
	</td>
	<td class="end">
		<xsl:value-of select="client-home-phone"/>
	</td>
</xsl:template>

<!--
	called from 'get-admin-menu.xsl'
-->
<!--xsl:template match="time-schedule" mode="schedule-list">
	<select id="admin_time-schedule">
		<option value="Edit a client">Edit Time Schedule</option>
		<option disabled="disabled" value=""></option>
		<xsl:apply-templates select="entry" mode="list"/>
	</select>
</xsl:template>

<xsl:template match="time-schedule/entry" mode="list">
	<xsl:choose>
		<xsl:when test="weekday/@handle = $entry-id and $current-page = 'admin-time-schedule'">
			<option value="{weekday/@handle}" selected="selected">
				<xsl:value-of select="weekday"/>
			</option>
		</xsl:when>
		<xsl:otherwise>
			<option value="{weekday/@handle}">
				<xsl:value-of select="weekday"/>
			</option>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template-->

</xsl:stylesheet>